using ExternalDSL;
using ExternalDSL.Initial;
using Machine.Specifications;
using Sprache;

namespace ExternalDSLTests.Initial
{
	public class When_parsing_an_alphanumeric_identifier
	{
		Because of = () => id =
		                   InitialParser.Identifier.Parse("name123");

		It should_find_an_id_called_name123 = () =>
		                                      id.ShouldEqual("name123");

		static string id;
	}

	public class When_parsing_an_alphanumeric_identifier_with_spaces
	{
		Because of = () =>
					 id = InitialParser.Identifier.Parse("name1 with2 spaces3");

		It should_only_get_the_text_up_to_the_space = () =>
													  id.ShouldEqual("name1");

		static string id;
	}

	public class When_parsing_an_alphanumeric_identifier_with_quotes
	{
		It should_throw_a_ParseException = () =>
										   typeof(ParseException).ShouldBeThrownBy(
											() => InitialParser.Identifier.Parse("\"name123\""));
	}

	public class When_parsing_quoted_text
	{
		Because of = () =>
		             quoted = InitialParser.QuotedText.Parse("\"1and rabble2\"");

		It should_find_1and_rabble2 = () =>
		                              quoted.ShouldEqual("1and rabble2");

		static string quoted;
	}

	public class When_test_is_parsed_from_a_string
	{
		Because of = () => test =
			InitialParser.Test.Parse("Foo \"Bar\"");

		It should_have_an_identifier_of_Foo = () =>
			test.Identifier.ShouldEqual("Foo");

		It should_have_a_QuotedText_of_Bar = () =>
			test.QuotedText.ShouldEqual("Bar");

		static Test test;
	}
}